package com.stu.day03;

import java.time.Year;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

/**
 * switch输出所求月份多少天
 * @author zy
 * @date 2025/1/25 14:43
 */
public class DayDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入年月份:");
        int year = sc.nextInt();
        int month = sc.nextInt();

        int day = switch (month){
            case 1,3,5,7,8,10,12 -> 31;
            case 4,6,9,11 -> 30;
            case 2 -> {
                int n = 28;
//                if(new GregorianCalendar().isLeapYear(year))
                if(Year.isLeap(year))  //更加高效
                    n++;
                yield n;  //yield返回计算结果
            }
            default -> 0;  //在赋值的情况下是必须要有的
        };
        System.out.printf("%d年%d月共有%d天",year,month,day);
        }
}
